﻿package mortal.game.view.mount.newMountModuel
{
    import Message.DB.Tables.*;
    import Message.Public.*;
    import __AS3__.vec.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.model.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.cd.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.common.tooltip.*;
    import mortal.game.view.mount.data.*;
    import mortal.mvc.core.*;

    public class MountRightPart extends GSprite
    {
        private var cdData:ICDData;
        private var _mountData:MountData;
        private var _tmountInfo:TMountConfig;
        private var _name:GTextFiled;
        private var _level:GImageBitmap;
        private var _expBar:BaseProgressBar;
        private var _levelUpItem:BaseItem;
        private var _levelUpNeedItemNum:GTextFiled;
        private var _levelTxt:GTextFiled;
        private var _levelUpTxt:GTextFiled;
        private var _rideSpeed:GTextFiled;
        private var _unRideSpeed:GTextFiled;
        private var _propName:GTextFiled;
        private var _expTips:GTextFiled;
        private var _comBat:BitmapNumberText;
        private var _levelUpSprite:GSprite;
        private var _addCombat:GTextFiled;
        private var _addCombatIcon:GBitmap;
        private var _servenActivitiesBtn:GLoadingButton;
        private var _vcAttributeName2:Vector.<String>;
        private var _vcAttributeValueText:Vector.<BitmapNumberText>;
        private var _vcAttributeAddValueText:Vector.<GTextFiled>;
        private var _vcAttributeAddValueBitMap:Vector.<GBitmap>;

        public function MountRightPart()
        {
            this._vcAttributeName2 = new Vector.<String>;
            this._vcAttributeValueText = new Vector.<BitmapNumberText>;
            this._vcAttributeAddValueText = new Vector.<GTextFiled>;
            this._vcAttributeAddValueBitMap = new Vector.<GBitmap>;
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            var _loc_3:GTextFiled = null;
            var _loc_4:BitmapNumberText = null;
            var _loc_5:GBitmap = null;
            super.createDisposedChildren();
            pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.AdvanceInfoBg, 0, 0, this));
            pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.mountText_1, 64, 45, this));
            pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.mountText_3, 66, 127, this));
            pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.mountText_4, 98, 322, this));
            pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.mountText_6, -366, 45, this));
            this._levelUpSprite = UICompomentPool.getUICompoment(GSprite);
            this.addChild(this._levelUpSprite);
            this.pushUIToDisposeVec(this._levelUpSprite);
            pushUIToDisposeVec(UIFactory.gTextField(Language.getString(35429), 64, 425, 60, 20, this._levelUpSprite));
            this._name = UIFactory.gTextField("", 129, 3, 141, 35, this, GlobalStyle.textFormatPutong.setColor(16777215).setSize(16).setBold(true));
            this._level = UIFactory.gImageBitmap("", 64, 2, this);
            this._comBat = UIFactory.bitmapNumberText(126, 71, "WizardCombatNum.png", 23, 30, -3, this, 13, BitmapNumberText.Mid);
            var _loc_1:* = GlobalStyle.textFormatItemGreen.left();
            _loc_1.size = 16;
            this._addCombat = UIFactory.gTextField("", 200, 70, 60, 25, this, _loc_1);
            this._addCombatIcon = UIFactory.gBitmap(ImagesConst.ascendingSortBtn_upSkin, 190, 76, this);
            this._addCombatIcon.visible = false;
            _loc_1 = GlobalStyle.textFormatLv.left();
            _loc_1.size = 12;
            this._rideSpeed = UIFactory.gTextField(Language.getStringByParam(30318, 11), -250, 45, 200, 25, this, _loc_1);
            this._unRideSpeed = UIFactory.gTextField(Language.getStringByParam(30319, 11), -250, 63, 200, 25, this, _loc_1);
            this._levelUpItem = UICompomentPool.getUICompoment(BaseItem);
            this._levelUpItem.x = 134;
            this._levelUpItem.y = 425;
            this._levelUpItem.setItemStyle(ItemStyleConst.Small, ImagesConst.PackItemBg, 2, 2);
            this.addChild(this._levelUpItem);
            this._levelUpNeedItemNum = UIFactory.gTextField("", 181, 436, 37, 20, this);
            this._propName = UIFactory.gTextField("", 54, 443, 80, 20, this._levelUpSprite, GlobalStyle.textFormatBai.center());
            this._levelTxt = UIFactory.gTextField("", 0, 0, 100, 20, this);
            this._expTips = UIFactory.gTextField(Language.getString(30321), 58, 416, 150, 20, null, null, true);
            _loc_1 = GlobalStyle.textFormatAnHuan.center();
            _loc_1.size = 14;
            _loc_1.bold = true;
            this._levelUpTxt = UIFactory.gTextField("", 29, 358, 200, 30, this, _loc_1);
            this._expBar = UICompomentPool.getUICompoment(BaseProgressBar);
            this._expBar.x = 8;
            this._expBar.y = 395;
            this._expBar.setBg(ImagesConst.MountBarBg, true, 246, 13);
            this._expBar.setProgress(ImagesConst.MountBar, true, 4, 4, 238, 13);
            this._expBar.setLabel(BaseProgressBar.ProgressBarTextOnlyShowValue, 23);
            this._expBar.isOverShowValue = true;
            this._expBar.mouseChildren = false;
            this._expBar.mouseEnabled = true;
            this.addChild(this._expBar);
            this._vcAttributeName2.length = 0;
            this._vcAttributeValueText.length = 0;
            this._vcAttributeAddValueText.length = 0;
            this._vcAttributeAddValueBitMap.length = 0;
            var _loc_2:* = MountConfig.instance.attribute;
            var _loc_6:int = 0;
            while (_loc_6 < _loc_2.length)
            {
                
                _loc_4 = UIFactory.bitmapNumberText(55 + _loc_6 % 2 * 134, 12 * (_loc_6 - _loc_6 % 2) + 164, "RoleInfoNum.png", 8, 10, -1, this, 14);
                this._vcAttributeValueText.push(_loc_4);
                pushUIToDisposeVec(_loc_4);
                _loc_3 = UIFactory.gTextField("", 102 + _loc_6 % 2 * 124, 12 * (_loc_6 - _loc_6 % 2) + 157, 60, 20, this, GlobalStyle.textFormatItemGreen);
                this._vcAttributeAddValueText.push(_loc_3);
                pushUIToDisposeVec(_loc_3);
                _loc_5 = UIFactory.gBitmap(ImagesConst.upgradeArrow, 92 + _loc_6 % 2 * 124, 12 * (_loc_6 - _loc_6 % 2) + 161, this);
                _loc_5.visible = false;
                this._vcAttributeAddValueBitMap.push(_loc_5);
                pushUIToDisposeVec(_loc_5);
                _loc_6++;
            }
            _loc_3 = UIFactory.gTextField("", -150, 45, 60, 20, this, GlobalStyle.textFormatItemGreen);
            this._vcAttributeAddValueText.push(_loc_3);
            pushUIToDisposeVec(_loc_3);
            _loc_5 = UIFactory.gBitmap(ImagesConst.ascendingSortBtn_upSkin, -162, 49, this);
            _loc_5.visible = false;
            this._vcAttributeAddValueBitMap.push(_loc_5);
            pushUIToDisposeVec(_loc_5);
            _loc_3 = UIFactory.gTextField("", -150, 63, 60, 20, this, GlobalStyle.textFormatItemGreen);
            this._vcAttributeAddValueText.push(_loc_3);
            pushUIToDisposeVec(_loc_3);
            _loc_5 = UIFactory.gBitmap(ImagesConst.ascendingSortBtn_upSkin, -162, 67, this);
            _loc_5.visible = false;
            this._vcAttributeAddValueBitMap.push(_loc_5);
            pushUIToDisposeVec(_loc_5);
            this.updateActiveBtn();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            if (this.cdData)
            {
                this.cdData.dispose();
                Cache.instance.cd.unregisterCDData(CDDataType.publicCD, "MountBlessClearCd");
                this.cdData = null;
            }
            this._levelUpTxt.dispose(param1);
            this._levelUpTxt = null;
            this._propName.dispose(param1);
            this._propName = null;
            this._expTips.dispose(param1);
            this._expTips = null;
            this._levelTxt.dispose(param1);
            this._levelTxt = null;
            this._levelUpItem.dispose(param1);
            this._levelUpItem = null;
            this._name.dispose(param1);
            this._name = null;
            this._level.dispose(param1);
            this._level = null;
            this._rideSpeed.dispose(param1);
            this._rideSpeed = null;
            this._unRideSpeed.dispose(param1);
            this._unRideSpeed = null;
            this._comBat.dispose(param1);
            this._comBat = null;
            this._expBar.dispose(param1);
            this._expBar = null;
            this._levelUpNeedItemNum.dispose(param1);
            this._levelUpNeedItemNum = null;
            this._addCombat.dispose(param1);
            this._addCombat = null;
            this._addCombatIcon.dispose(param1);
            this._addCombatIcon = null;
            if (this._servenActivitiesBtn)
            {
                this._servenActivitiesBtn.dispose(param1);
                this._servenActivitiesBtn = null;
            }
            this._mountData = null;
            this._tmountInfo = null;
            this._vcAttributeName2.length = 0;
            this._vcAttributeValueText.length = 0;
            this._vcAttributeAddValueText.length = 0;
            this._vcAttributeAddValueBitMap.length = 0;
            super.disposeImpl(param1);
            return;
        }// end function

        private function updateActiveBtn() : void
        {
            if (Cache.instance.openServerSevenDay.getTargetTypeName() == "坐骑")
            {
                if (this._servenActivitiesBtn == null)
                {
                    this._servenActivitiesBtn = UIFactory.gLoadingButton(ResFileConst.sevenDayActiveBtn, 200, 424, 44, 44, this);
                }
                this._servenActivitiesBtn.configEventListener(MouseEvent.CLICK, this.openServenDayWin);
            }
            else if (this._servenActivitiesBtn)
            {
                this._servenActivitiesBtn.removeEventListener(MouseEvent.CLICK, this.openServenDayWin);
                this._servenActivitiesBtn.dispose();
                this._servenActivitiesBtn = null;
            }
            return;
        }// end function

        private function openServenDayWin(event:MouseEvent) : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.RebateOpenServerSevenDayModule, null));
            return;
        }// end function

        private function getMountBlessToolTip() : ToolTipInfo
        {
            var _loc_1:BlessData = null;
            if (this._mountData)
            {
                _loc_1 = new BlessData();
                _loc_1.bless = this._mountData.sPublicMount.bless;
                _loc_1.blessClear = this._mountData.tMountConfig.blessClear;
                _loc_1.leftSeconds = (this._mountData.sPublicMount.lastAdvanceSuccessDt.time - ClockManager.instance.nowDate.time) * 0.001;
                _loc_1.type = Language.getString(35430);
                return new ToolTipInfo(TooltipType.Bless, _loc_1);
            }
            return null;
        }// end function

        private function updateCd() : void
        {
            var _loc_1:Number = NaN;
            if (this._mountData.tMountConfig.blessClear && this._mountData.sPublicMount.bless > 0)
            {
                _loc_1 = this._mountData.sPublicMount.lastAdvanceSuccessDt.time - ClockManager.instance.nowDate.time;
                if (_loc_1 > 0)
                {
                    if (this.cdData == null)
                    {
                        this.cdData = Cache.instance.cd.registerCDData(CDDataType.publicCD, "MountBlessClearCd", this.cdData);
                    }
                    this.cdData.totalTime = _loc_1;
                    this.cdData.beginTime = 0;
                    this.cdData.startCoolDown();
                    this.cdData.addFinishCallback(this.clearBless);
                }
                else
                {
                    this.clearBless();
                }
            }
            else if (this.cdData)
            {
                this.cdData.dispose();
                Cache.instance.cd.unregisterCDData(CDDataType.publicCD, "MountBlessClearCd");
                this.cdData = null;
            }
            return;
        }// end function

        private function clearBless() : void
        {
            this._expBar.setValue(0, 100);
            this._mountData.sPublicMount.bless = 0;
            if (this.cdData)
            {
                this.cdData.dispose();
                Cache.instance.cd.unregisterCDData(CDDataType.publicCD, "MountBlessClearCd");
                this.cdData = null;
            }
            return;
        }// end function

        public function updateMountInfo(param1:MountData, param2:TMountConfig) : void
        {
            this._mountData = param1;
            this._tmountInfo = param2;
            this._expBar.toolTipData = this.getMountBlessToolTip;
            this._level.imgUrl = "levelIcon_" + this._mountData.sPublicMount.code + ".png";
            this._rideSpeed.text = Language.getStringByParam(30318, this._mountData.tMountConfig.addSpeed);
            this._unRideSpeed.text = Language.getStringByParam(30319, this._mountData.tMountConfig.speed);
            this._levelUpItem.itemData = new ItemData(int(this._mountData.tMountConfig.propConsume));
            if (this._mountData.sPublicMount.code == MountUtil.maxMountLevel)
            {
                this._levelUpNeedItemNum.visible = false;
                this._levelTxt.text = "";
                this._levelUpTxt.text = Language.getStringByParam(35431, MountUtil.maxMountLevel);
            }
            else
            {
                this._levelUpNeedItemNum.visible = true;
                this._levelTxt.text = "";
                this._levelUpTxt.text = "";
            }
            this.updateAttrData();
            this.blessUpdate();
            this.updateCd();
            this.updateName(this._tmountInfo.code);
            this.updateLevelUpItem();
            return;
        }// end function

        public function updateName(param1:int) : void
        {
            this._name.text = this._mountData.tMountConfig.name;
            return;
        }// end function

        public function updateAttrData() : void
        {
            var _loc_3:int = 0;
            var _loc_1:* = MountConfig.instance.attribute;
            var _loc_2:* = _loc_1.length;
            var _loc_4:int = 0;
            while (_loc_4 < _loc_2)
            {
                
                this._vcAttributeValueText[_loc_4].text = MountUtil.mountAttrByName(_loc_1[_loc_4]).toString();
                _loc_4++;
            }
            this.updateCombat();
            return;
        }// end function

        public function updateCombat() : void
        {
            this._comBat.text = MountUtil.mountCombat.toString();
            return;
        }// end function

        public function blessUpdate() : void
        {
            if (this._mountData.sPublicMount.code == 10)
            {
                this._expBar.setValue(0, 100);
                this._expTips.visible = false;
            }
            else
            {
                this._expBar.setValue(this._mountData.sPublicMount.bless, this._mountData.tMountConfig.blessMax);
                this._expTips.visible = this._mountData.tMountConfig.blessClear == 1 && this._mountData.sPublicMount.bless > 0 ? (true) : (false);
            }
            return;
        }// end function

        public function showAttrUp() : void
        {
            var _loc_3:int = 0;
            var _loc_1:* = MountConfig.instance.attribute;
            var _loc_2:* = _loc_1.length;
            var _loc_4:* = new MountData((this._mountData.sPublicMount.code + 1));
            var _loc_5:int = 0;
            while (_loc_5 < _loc_2)
            {
                
                _loc_3 = _loc_4.tMountConfig[_loc_1[_loc_5]] - this._mountData.tMountConfig[_loc_1[_loc_5]];
                this._vcAttributeAddValueText[_loc_5].text = _loc_3 > 0 ? (_loc_3.toString()) : ("");
                this._vcAttributeAddValueBitMap[_loc_5].visible = _loc_3 > 0 ? (true) : (false);
                _loc_5++;
            }
            _loc_3 = _loc_4.tMountConfig.addSpeed - this._mountData.tMountConfig.addSpeed;
            this._vcAttributeAddValueText[_loc_5].text = _loc_3 > 0 ? (_loc_3.toString()) : ("");
            this._vcAttributeAddValueBitMap[_loc_5].visible = _loc_3 > 0 ? (true) : (false);
            _loc_3 = _loc_4.tMountConfig.speed - this._mountData.tMountConfig.speed;
            this._vcAttributeAddValueText[(_loc_5 + 1)].text = _loc_3 > 0 ? (_loc_3.toString()) : ("");
            this._vcAttributeAddValueBitMap[(_loc_5 + 1)].visible = _loc_3 > 0 ? (true) : (false);
            _loc_3 = MountUtil.nextMountAddCombat;
            this._addCombat.text = _loc_3 > 0 ? (_loc_3.toString()) : ("");
            this._addCombatIcon.visible = _loc_3 > 0 ? (true) : (false);
            return;
        }// end function

        public function hideAttrUp() : void
        {
            var _loc_1:* = this._vcAttributeAddValueText.length;
            var _loc_2:int = 0;
            while (_loc_2 < _loc_1)
            {
                
                this._vcAttributeAddValueText[_loc_2].text = "";
                this._vcAttributeAddValueBitMap[_loc_2].visible = false;
                _loc_2++;
            }
            this._addCombat.text = "";
            this._addCombatIcon.visible = false;
            return;
        }// end function

        private function getAdvanceItem(param1:int) : int
        {
            var _loc_2:Object = null;
            var _loc_3:int = 0;
            var _loc_6:ItemData = null;
            var _loc_7:int = 0;
            var _loc_4:* = Cache.instance.pack.backPackCache.getItemsByGroupCategoryAndType(EGroup._EGroupStuff, EStuff._EStuffAdvance, param1);
            var _loc_5:* = _loc_4.length;
            while (_loc_7 < _loc_5)
            {
                
                _loc_6 = _loc_4[_loc_7] as ItemData;
                if (ItemsUtil.isPrescriOutTime(_loc_6))
                {
                }
                else if (_loc_6.itemInfo.effectEx == 1)
                {
                }
                else if (this._mountData.mountLevel >= _loc_6.itemInfo.effect)
                {
                    _loc_3 = _loc_3 + _loc_6.itemAmount;
                }
                _loc_7++;
            }
            return _loc_3;
        }// end function

        public function updateLevelUpItem() : void
        {
            var _loc_2:int = 0;
            var _loc_3:int = 0;
            var _loc_4:int = 0;
            var _loc_5:int = 0;
            var _loc_6:Array = null;
            var _loc_1:* = MountUtil.isHasBlessItem(EAdvanceType._EAdvanceMountAdvanced);
            if (_loc_1)
            {
                this._levelUpItem.itemData = _loc_1;
                this._propName.htmlText = ItemsUtil.getItemName(this._levelUpItem.itemData, "[{0}]");
                this._levelUpItem.amount = _loc_1.serverData.itemAmount;
                this._levelUpNeedItemNum.text = "*" + 1;
                this._levelUpItem.bitmapEnable = true;
            }
            else
            {
                _loc_2 = this.getAdvanceItem(EAdvanceType._EAdvanceMountAdvanced);
                _loc_3 = this.getAdvanceItem(EAdvanceType._EAdvanceTypeAllRoundUp);
                _loc_4 = _loc_2 + _loc_3;
                _loc_5 = this._mountData.tMountConfig.propNum;
                if (_loc_2 == 0 && _loc_3 >= _loc_5)
                {
                    _loc_6 = Cache.instance.pack.backPackCache.getItemsByGroupCategoryAndType(EGroup._EGroupStuff, EStuff._EStuffAdvance, EAdvanceType._EAdvanceTypeAllRoundUp);
                    this._levelUpItem.itemData = _loc_6[0];
                }
                else
                {
                    this._levelUpItem.itemData = new ItemData(int(this._mountData.tMountConfig.propConsume));
                }
                this._propName.htmlText = ItemsUtil.getItemName(this._levelUpItem.itemData, "[{0}]");
                if (_loc_4 >= _loc_5)
                {
                    this._levelUpItem.bitmapEnable = true;
                    this._levelUpItem.amount = _loc_4;
                }
                else
                {
                    this._levelUpItem.bitmapEnable = false;
                    this._levelUpItem.setAmountLabel("<font color=\'#df2121\'>" + _loc_4 + "</font>");
                }
                this._levelUpNeedItemNum.text = "*" + _loc_5;
            }
            return;
        }// end function

    }
}
